package cn.chencaiju.day10;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Test;

public class FileOutPutStreamTest {
	@Test public void testStreamAppend() {
		File dir=new File("data/d1");
		dir.mkdirs();//创建多级文件夹	
		System.out.println(dir.getPath());

		File file=new File(dir,"test.txt");//创建文件
		
		//往文件中追加内容
		try {
			FileOutputStream fo=new FileOutputStream(file,true);
			fo.write('A');
			fo.write("sdd".getBytes());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@Test public void testStream() {
		File dir=new File("data");
		dir.mkdir();//创建多级文件夹	
		System.out.println(dir.getPath());

		File file=new File(dir,"test.txt");//创建文件
		
		//往文件中写入内容
		try {
			FileOutputStream fo=new FileOutputStream(file);
			fo.write('A');
			fo.write("sdd".getBytes());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}
	
}
